home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 08 (1988)(MegaDisc Digital Publishing)(AU)[WB].zip / MegaDisc 08 (1988)(MegaDisc Digital Publishing)(AU)[WB].adf / TUTORIALS / BASIC / Basic_Tute < prev    next >
Text File  |  1988-05-28  |  17KB  |  438 lines

  1.   AMIGABASIC TUTORIAL PARTS 4-6
  2.  
  3.                       By Jonathan Potter.
  4.  
  5.  
  6.   DRAWING FUNCTIONS
  7.  
  8.   All of the AmigaBASIC drawing functions take the
  9.   form (x,y) or (x1,y1)-(x2,y2).
  10.   A brief run down of them follows.
  11.  
  12.   CIRCLE [STEP] (x,y),radius [,colour id [,start,end[,aspect]]]
  13.  
  14.           (x,y) are the coordinates for the origin of the circle.
  15.           <radius> is the radius in pixels.
  16.           <colour id> is the drawing colour
  17.           <start> and <end> refer to the start and end angles in radians,
  18.   and range from -2pi to 2pi. These angles allow the user to specify where
  19.   an ellipse starts and ends. If <start> or <end> are negative, the circle
  20.   is connected to the origin with a line, and the angles treated as
  21.   positives. <aspect> is the ratio of the width to height of one pixel
  22.   (eg, the aspect ratio of an 1081 monitor is 2.25:1, so the <aspect> would
  23.   be 1/2.25, which is .44. This is the default). The [STEP] option is
  24.   present in most drawing commands, and indicates that the x and y
  25.   coordinates are relative to the current, or last referenced coordinates
  26.   of the pen. (e.g if the last referenced point was (10,10), the command
  27.   CIRCLE STEP (20,15),10 would draw a circle with origin (30,25) and radius
  28.   10).
  29.  
  30.           EXAMPLES
  31.  
  32.             CIRCLE (100,100),100
  33.               - circle with radius 100, origin (100,100)
  34.             CIRCLE (300,30),50,4,,,.5
  35.               - circle with radius 50, origin (300,30), colour 4, with
  36.                 aspect ratio of .5 (i.e pixels twice high as wide.)
  37.             CIRCLE (300,100),100,,1.5,4.5
  38.               - circle with radius 100, origin (300,100), starting at 1.5
  39.                 rads, and ending at 4.5 rads.
  40.  
  41.   LINE [[STEP](x1,y1)-[STEP](x2,y2),[colour-id] [,b[f]]
  42.  
  43.           (x1,y1) are the starting coordinates for the line. As in circle,
  44.   STEP indicates to refer to the pen position.
  45.           (x2,y2) are the ending coordinates for the line. This time, STEP
  46.   refers to the (x1,y1) coordinates.
  47.           <colour-id> is the drawing colour. The b paramater makes a box
  48.   be drawn instead of a line. In this case, (x1,y1) are the upper-left
  49.   coordinates, and (x2,y2) the lower-right.
  50.           The bf paramater causes the box to be filled in.
  51.  
  52.           EXAMPLES
  53.  
  54.             LINE (10,10)-(100,100),3
  55.               - draws a line from (10,10) to (100, 100) in colour 3
  56.             LINE (100,100)-(150,120),,bf
  57.               - draws a filled in box with upper-left coordinates (100,100)
  58.                 and lower right coordinates (150,120)
  59.             LINE STEP (10,10)- STEP (30,50),,b
  60.               - draws a box with upper-left coordinates (10,10) from last
  61.                 referenced position, and lower- right coordinates (30,50)
  62.                 from (10,10) the first coordinates.
  63.  
  64.   PAINT [STEP](x,y)[,paintColour-id
  65.         [,borderColour-id]]
  66.  
  67.           (x,y) are the coordinates of any point within the area to be
  68.   painted (filled) STEP again refers to a relative point.
  69.           <paintColour-id> is the colour that the area is to be painted.
  70.           <borderColour-id> is the colour of the border surrounding the
  71.   to-be-painted area (i.e the colour at which filling stops.) If this value
  72.   is not specified, <paintColour-id> is used.
  73.  
  74.           EXAMPLES
  75.  
  76.             PAINT (100,100),5,3
  77.               - fills in an area with an interior point (100,100), with
  78.   colour 5, stopping at colour 3.
  79.             PAINT (50,300),2
  80.               - fills an area with interior point (50,300) with colour 2,
  81.   not stopping until colour 2 is found.
  82.  
  83. BASIC TUTORIAL PART 5
  84.  
  85.  
  86.   PALETTE <colour-id>,<redvalue>,<greenvalue>,<bluevalue>
  87.  
  88.           PALETTE allows you to set the colour registers for your programme.
  89.           <colour-id> is the colour register, a value from 0 to 31.  (0 is
  90.   the background colour).
  91.           <redvalue>
  92.           <greenvalue>
  93.           <bluevalue> are values from 0.00 to 1.00, indicating a decimal
  94.   percentage of red, green and blue. Combined these paramaters define a
  95.   colour.
  96.  
  97.           EXAMPLES
  98.  
  99.           PALETTE 0,1,1,1 - sets the background colour to white.
  100.           PALETTE 1,1,.6,0 - sets register 1 to orange.
  101.           PALETTE 18,.8,0,.93 - sets register 18 to purple.
  102.  
  103.  
  104.   POINT (x,y)
  105.  
  106.           POINT returns the colour id of the point at (x,y)
  107.  
  108.           EXAMPLES
  109.  
  110.           PRINT POINT (100,100) - prints the colour id at the point
  111.   (100,100)
  112.           IF POINT(300,10)=0 THEN main - goes to main: if the
  113.           point at (300,10) is blank (0 is the default background
  114.           colour)
  115.  
  116.  
  117.   PSET [STEP] (x,y) [,<colour id>]
  118.  
  119.           PSET sets a point (x,y) in the current output window to
  120.           the current foreground colour (default is colour id 1)
  121.           if none is specified, otherwise to the colour specified
  122.           by <colour id>. As with other commands, STEP specifies
  123.           a location relative to the last referenced point, rather
  124.           than an absolute point.
  125.  
  126.           EXAMPLES
  127.  
  128.           PSET (100,100),3 - sets point at (100,100) to colour 3.
  129.           PSET STEP (300,-10) - sets point 300 pixels to the left,
  130.           and ten pixels up from the last referenced point to
  131.           the current foreground colour.
  132.  
  133.  
  134.   PRESET [STEP] (x,y) [,<colour id>]
  135.  
  136.           PRESET is identical to PSET in every way except one -
  137.           if <colour id> is omitted the point is set to
  138.           the current background colour, rather than the foreground.
  139.  
  140.           EXAMPLES
  141.  
  142.           PRESET (100,100),3 - does exactly the same thing as
  143.           the first example for PSET.
  144.           PRESET STEP (300,-10) - sets point 300 pixels to the
  145.           left, and ten pixels up from the last referenced
  146.           point (as did the second example for PSET) but in
  147.           the background colour rather than the foreground colour.
  148.  
  149.  
  150.   AREA [STEP] (x,y)
  151.  
  152.           AREA defines a point of a polygon to be acted upon
  153.           by AREAFILL. The (x,y) parameters specify one of up
  154.           to twenty points that form a polygon. If STEP is
  155.           specified, (x,y) are relative from the last AREA (x,y)
  156.           parameters.
  157.           AREA is reset after AREAFILL has been executed, so if
  158.           you wish to AREAFILL the same polygon again, you
  159.           must redefine it with AREA.
  160.  
  161.           EXAMPLES
  162.  
  163.           AREA (10,10):AREA (100,10):AREA (100,50): AREA(10,50) -
  164.           defines a square with corners at (10,10), (100,10),
  165.           (100,50) and (10,50).
  166.  
  167.           AREA (100,10):AREA STEP (50,0):AREA STEP (0,50):
  168.           AREA STEP (-50,0) - defines a square with sides of 50
  169.           (its corners are at (100,10), (150,10), (150,60) and
  170.           (100,60).)
  171.  
  172.   AREAFILL [mode]
  173.  
  174.           AREAFILL alters the interior of the polygon defined by
  175.           AREA statements.
  176.           The [mode] parameter is either 0 or 1.
  177.           0 - fills the area with the area pattern established
  178.           by a PATTERN command.
  179.           1 - inverts (reverses colours in the) the area.
  180.           0 is the default parameter - if no [mode] is specified,
  181.           the pattern defined by PATTERN will be used.
  182.  
  183.           EXAMPLES
  184.  
  185.           AREAFILL 1 - will invert (reverse) the colours in a
  186.           defined area. This, for example, generates the same
  187.           effect as clicking with the left mouse button and
  188.           holding on a Boolean type gadget (e.g the CANCEL of a
  189.           system request). Here is an example of a gadget in
  190.           AmigaBASIC, to demonstrate one of the uses of AREAFILL 1.
  191.  
  192.   gadget:
  193.   'AmigaBasic gadget (C) 1988 Jonathan Potter
  194.   LINE (10,10)-(70,40),1,b:LINE (12,12)-(68,38),3,b
  195.   LOCATE 3,3:PRINT"CLICK!"
  196.   waitforclick:
  197.   IF MOUSE(0)=0 THEN waitforclick
  198.   m1=MOUSE(1):m2=MOUSE(2)
  199.   IF m1<10 OR m1>70 OR m2<10 OR m2>40 THEN
  200.           WHILE MOUSE(0)<>0:SLEEP:WEND
  201.           GOTO waitforclick
  202.   END IF
  203.   AREA (10,10):AREA (70,10):AREA (70,40):AREA (10,40)
  204.   AREAFILL 1:out=0
  205.   WHILE MOUSE(0)<>0
  206.       m1=mouse(1):m2=mouse(2)
  207.       IF out=0 THEN IF m1<10 or m1>70 or m2<10 or m2>40 THEN
  208.            AREA(10,10):AREA (70,10):AREA (70,40):AREA (10,40)
  209.            out=1: AREAFILL 1
  210.       END IF
  211.       IF out=1 THEN IF m1>9 and m1<71 and m2>9 and m2<41 THEN
  212.            AREA(10,10):AREA (70,10):AREA (70,40):AREA (10,40)
  213.            out=0:AREAFILL 1
  214.       END IF
  215.   WEND
  216.   IF out=0 THEN
  217.       AREA(10,10):AREA (70,10):AREA (70,40):AREA (10,40):AREAFILL 1
  218.       LOCATE 10,1:PRINT"You Clicked!":END
  219.   END IF
  220.   IF out=1 THEN out=0:GOTO waitforclick
  221.  
  222.  
  223.   If that routine uses commands you are unfamiliar with,
  224.   don't worry. It is likely they will be covered in later
  225.   tutorials. That routine was just to demonstrate one of
  226.   the uses of AREAFILL 1.
  227.  
  228.           AREAFILL 0 - this will fill in the defined area with
  229.           the pattern specified by PATTERN.
  230.  
  231.   PATTERN [<line pattern>][,<area pattern>]
  232.  
  233.           PATTERN allows textured fills of polygons, and
  234.           lines and text.
  235.  
  236.   <line pattern> is a hexadecimal number that defines a 16 bit
  237.   value to be used for line drawing.
  238.   <area pattern> is the name of an integer array containing
  239.   the pattern. The array defines a 16 bit wide by 2^n high
  240.   value to be used for AREAFILL 0 where n is any integer from
  241.   1 to 5 inclusive. The array contains 2^n elements.
  242.  
  243.   Determining the 16 bit and 16X2^n bit values is somewhat
  244.   reminiscent of designing sprites on the C64.
  245.   Each 16 bit long line (only one in the <line pattern>) consists
  246.   of on and off pixels. e.g for a dotted line effect the
  247.   binary value would be 1010101010101010. This must then be
  248.   converted to a hex value which in this case is &HAAAA (each of
  249.   the four groups of four bits (1010) yields in this case a decimal
  250.   10, which is A in hex.)
  251.   If the command PATTERN &HAAAA was executed, subsequent lines and
  252.   text drawn would be dotted (on/off/on/off....). This would
  253.   continue until a solid <line pattern> was defined (1111111111111111)
  254.   which is hex &HFFFF. (e.g PATTERN &HFFFF)
  255.   If you defined an array, say for example pat%, like this:
  256.  
  257.           DIM pat%(1)
  258.           pat%(0)=&HAAAA  (&HAAAA is 1010101010101010)
  259.           pat%(1)=&H5555  (&H5555 is 0101010101010101)
  260.  
  261.   and then executed the command
  262.  
  263.           PATTERN ,pat%
  264.  
  265.   any subsequent AREAFILL 0 commands would fill the area with
  266.   the pattern defined in array pat%, in this case, a dotted
  267.   pattern. This would continue until
  268.  
  269.           DIM pat%(1)
  270.           pat%(0)=&HFFFF
  271.           pat%(1)=&HFFFF
  272.           PATTERN ,pat%
  273.  
  274.   was executed, resetting the fill pattern to solid.
  275.  
  276. BASIC TUTORIAL PART 6
  277.  
  278.   GET (<x1>,<y1>)-(<x2>,<y2>),<array-name>[(index list]
  279.  
  280.           GET has two functions - a graphical function
  281.           (described below), and an I/O function (which will
  282.           be described in later tutorials).
  283.           GET is used in conjunction with PUT (see below) to
  284.           transferring graphic images from one part of the screen
  285.           to another.
  286.           (<x1>,<y1>) and (<x2>,<y2>) are the top left and bottom
  287.           right corners respectively of the rectangle you wish to
  288.           GET.
  289.           <array-name> is the name of the array that will hold
  290.           the image. The array can be any type except a string,
  291.           but the contents of the array will be meaningless when
  292.           directly interpreted, unless the array is an integer
  293.           (e.g array%). The array must
  294.           The required dimension of the array is calculated by
  295.           the following formula :
  296.  
  297.           (6+((y+1)*2*INT((x+16)/16)*D)/BYTES
  298.  
  299.           where x and y are the lengths of the horizontal and
  300.           vertical sides of the rectangle (x and y can be
  301.           calculated like so: x=x2-x1 and y=y2-y1), and D is
  302.           the screen depth (see AMIGABASIC TUTORIAL PART 1 for a
  303.           discussion on depth) for which 2 is the default.
  304.           BYTES is the number of bytes per element of an array,
  305.           which are:
  306.  
  307.           integer - 2 bytes
  308.           single precision - 4 bytes
  309.           double precision - 8 bytes
  310.  
  311.           Therefore, if you wished to
  312.  
  313.           GET (10,20)-(30,40),ARRAY%
  314.  
  315.           from the normal Workbench screen (depth of 2), the number
  316.           of elements required for ARRAY% is
  317.  
  318.           (6+((20+1)*2*(INT((20)+16)/16))*2)/2
  319.  
  320.           which works out to be 87 elements.
  321.           Therefore, you would have to DIM ARRAY%(87)
  322.  
  323.           The <index-list> allows you to define multiple images
  324.           in a multidimensional array.
  325.  
  326.  
  327.   PUT [STEP] (<x>,<y>), <array-name> [(index-list)]
  328.              [action-verb]
  329.  
  330.           PUT, like GET, has a graphical and an I/O function.
  331.           The I/O function will be discussed in future tutorials.
  332.           PUT is used to place an image defined by GET from the
  333.           array <array-name> on the screen, with top left
  334.           coordinates (<x>,<y>). The <index-list> allows mutiple
  335.           images in a multidimensional array. STEP again refers
  336.           to a point relative from the last referenced point,
  337.           rather than an absolute point.
  338.           <action-verb> is one of PSET, PRESET, AND, OR or XOR,
  339.           and defines how the placement will interact with
  340.           the screen.
  341.           PSET will place the image on the screen, totally
  342.           obscuring anything underneath it.
  343.           PRESET will do the same as PSET, but will invert
  344.           (reverse) the colours.
  345.           AND will perform a logical And on the image and what
  346.           is already on the screen, and display the result.
  347.           OR will perform a logical Or on the image and what is
  348.           already on the screen, and display the result.
  349.           XOR (which is the default) will place the image over
  350.           the top of whatever is already on the screen, but will
  351.           let what is there show through.
  352.  
  353.           EXAMPLES
  354.  
  355.           PUT (20,90),ARRAY%,PSET - places the image from ARRAY% on
  356.           the screen at (20,90) obscuring what is already there.
  357.           PUT STEP (10,10),ARRAY% - places the image from ARRAY% on
  358.           the screen (10,10) from the last referenced point.
  359.  
  360.  
  361.   COLOR [<foreground colour id>] [,<background colour id>]
  362.  
  363.           COLOR allows you to set the current foreground and
  364.           background drawing colours.
  365.           <foreground colour id> is a value from 0 to 31, which
  366.           corresponds to a colour register set by the PALETTE
  367.           command.
  368.           <background colour id> is a value from 0 to 31, which
  369.           corresponds to a colour register set by the PALETTE
  370.           command.
  371.           All graphics and text will be drawn in the current
  372.           foreground colour, unless specified otherwise.
  373.  
  374.           EXAMPLES
  375.  
  376.           COLOR 1,0 - this is the default colour setup, which,
  377.           with the default system colours, produces white text
  378.           on a blue background.
  379.           COLOR 0,1 - with the default system colours, this
  380.           produces blue text on a white background.
  381.           COLOR 3,2 - foreground colour 3, background colour 2
  382.           COLOR 8 - foreground colour 8, background colour
  383.           unchanged.
  384.           COLOR ,9 - foreground colour unchanged, background
  385.           colour 9.
  386.  
  387.  
  388.   WINDOW CLOSE <window-id>
  389.   WINDOW OUTPUT <window-id>
  390.   SCREEN CLOSE <screen-id>
  391.   WINDOW <n>
  392.  
  393.           These four commands were inadvertantly left out of
  394.           previous tutorials. Briefly,
  395.  
  396.           WINDOW CLOSE will close a window once it has been opened.
  397.           <window-id> is the id of the window.
  398.           WINDOW OUTPUT will direct all screen output (text, graphics,
  399.           etc.) to the window <window-id>. Default for this
  400.           is 1 (the default AmigaBASIC output window).
  401.           SCREEN CLOSE will close a screen once it has been opened.
  402.           <screen-id> is the id of the screen.
  403.           WINDOW <n> will return information about the status
  404.           and size of the current output window. <n> is any number
  405.           from 0 to 8.
  406.  
  407.           <n> value   Information returned
  408.           0           The window-id of the selected output window.
  409.           1           The window-id of the current output window.
  410.           2           The width of the current output window.
  411.           3           The height of the current output window.
  412.           4           The x coordinate in the current output window
  413.                       where the next character is drawn.
  414.           5           The y coordinate in the current output window
  415.                       where the next character is drawn.
  416.           6           The maximum legal colour for the current output
  417.                       window.
  418.           7           A pointer to the INTUITION WINDOW record for the
  419.                       current output window.
  420.           8           A pointer to the RASTPORT record for the current
  421.                       output window.
  422.  
  423.                These last two are not necessary for the casual programmer,
  424.    however, if you require information about them, see the manual
  425.   "Intuition: The Amiga User Interface"
  426.  
  427.                EXAMPLES
  428.  
  429.                WINDOW CLOSE 1 - will close window 1 (when AmigaBASIC is
  430.    first started this is the output window)
  431.                WINDOW OUTPUT 3 - will direct screen output to window 3.
  432.                SCREEN CLOSE 2 - will close screen 2.
  433.                PRINT WINDOW(2)*WINDOW(3) - will return the area in pixels of
  434.    the current output window (useful!)
  435.  
  436. XXXXXXXXXXXXXXXXXXXXXXXXXXX END OF BASIC_TUTE XXXXXXXXXXXXXXXXXXXXXXXXXXXX
  437.  
  438.